package com.lz.webflux.project.api.service;

import org.xhtmlrenderer.simple.ImageRenderer;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import java.io.IOException;

public class HtmlToImageConverter {

    public static void convertToImage(String html, String imagePath) throws IOException {

        BufferedImage image = ImageRenderer.renderToImage(html,"D:/",300);
        ImageIO.write(image, "png", new File(imagePath));
    }

    public static void main(String[] args) {
        String html = HtmlGenerator.generateHtml();
        String imagePath = "output.png";
        try {
            convertToImage(html, imagePath);
            System.out.println("Image created: " + imagePath);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
